package com.funny.stock.trade.dao.repo;

import com.funny.stock.trade.dao.pojo.DayTradeRecordDO;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

/**
 * @Description  
 * @Author  pengl
 * @Date 2020-05-17 
 */

@Repository
public interface DayTradeRecordRepo extends JpaRepository<DayTradeRecordDO,Long>, JpaSpecificationExecutor<DayTradeRecordDO>{
//    List<DayTradeRecordDO> findByPlanIdAndPlanTypeAndType(Long planId, String planType,Integer type);
//
//    Page<DayTradeRecordDO> findByPlanIdAndPlanType(Long planId, String planType, Pageable pageable);
//
//    Page<DayTradeRecordDO> findByPlanIdAndStockCodeAndPlanType(Long planId, String code, String planType, Pageable pageable);


    @Query(nativeQuery = true,
            value = "SELECT * FROM `t_day_trade_record` \n" +
            "WHERE compose_id = ?1\n" +
            "AND plan_id = ?2\n" +
            "AND plan_type = ?3\n" +
            "AND stock_code = ?4\n" +
            "AND TYPE = ?5",
            countQuery = "SELECT count(*) FROM `t_day_trade_record` \n" +
            "WHERE compose_id = ?1\n" +
            "AND plan_id = ?2\n" +
            "AND plan_type = ?3\n" +
            "AND stock_code = ?4\n" +
            "AND TYPE = ?5")
    Page<DayTradeRecordDO> findByTradeType(Long composeId, Long planId, String playType, String code, Integer type, Pageable pageable);
}
